<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>推荐使用备件详细信息</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		
		<style type="text/css">
			.item_box .item{
				overflow: auto;
			}
			.item_box .item .bar{
				height: auto;
			}
			.item_box .item .bar .number{
				word-break: break-all;
			}
			.item_box .item .text{
				overflow: hidden;
				height: auto;
			}
			.item_box .item .text span{
				width: auto;
				word-break: break-all;
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">推荐使用备件详细信息</h1>
		</header>
		<div class="mui-content">
			<div class="item_box" id="beijian">
				<!-- <div class="item" onclick="app.jumpTo('../service/fwtzbjxx.html','view/service/details.html')">
					<p class="bar"><span class="number">备件名称：1170001</p>
					<div class="text">2132345465768<span>备件号：</span></div>
					<div class="text">1<span>数量：</span></div>
				</div>	 -->
			</div>
			
			<div class="btn_box" id="anniu" style="display: none;">
				<span class="fl red one" id="shenqing">备件借货申请</span>
			</div>
			
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var ServiceNoticeId
			var serviceNo
			var planId
			var recommendData = []; //推荐备件信息，将存入备件申请的缓存中
			var prev
			
			(function($, doc) {
				$.init();

				$.plusReady(function() {
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					// 获取上一个页面传过来的参数并显示到页面
					ServiceNoticeId = self.ServiceNoticeId;
					serviceNo = self.serviceNo;
					planId = self.planId;
					prev = self.prev;

					// 获取详情的方法
					getDetails();

					// 备件借贷申请
					h("#shenqing").tap(function() {
						// 推荐备件信息存到缓存
						var applyPartsKey = "FSE_ITEM_KEY_APPLY_PARTS";
						h.setItem(applyPartsKey, JSON.stringify(recommendData));
						// 跳转申请页
						app.jumpTo("/view/workArea/parts/applyParts.html", "view/workArea/parts/applyParts.html", {
							"serviceNo" : serviceNo,
							"ServiceNoticeId": ServiceNoticeId,
						});
					})

				});

				// 获取详情的方法
				function getDetails() {
					if(prev && (prev == "updateCase" || prev == "closedList")){
						h("#anniu").hide();
					} else {
						getPlanState();
					}
					
					ajaxGet(BASE_URL + "cc/ServicePart/getServicePart", {
						"ServiceNoticeId": ServiceNoticeId
					}, function(data) {
						if (data.code == 200) {
							h("#beijian").html("");
							var html = "";
							if (data.data && data.data.length > 0) {
								for(var i=0;i<data.data.length;i++){
									var das = data.data[i];
									var partName = das.partName?das.partName:"无";
									var partNo = das.partNo?das.partNo:"无";
									var qty = das.qty?das.qty:"无";
									var price = das.price?das.price:"无";
									var totalPrice = das.totalPrice?das.totalPrice:"无";
									var remark = das.remark?das.remark:"无";
									var partremark = das.partremark?das.partremark:"无";
									
									html += '<div class="item">'
									html += '<p class="bar"><span class="number">备件名称：</span>'+partName+'</p>'
									html += '<div class="text"><span>备件号：</span>'+partNo+'</div>'
									html += '<div class="text"><span>数量：</span>'+qty+'</div>'
									html += '<div class="text"><span>单价：</span>'+price+'</div>'
									html += '<div class="text"><span>总价：</span>'+totalPrice+'</div>'
									html += '<div class="text"><span>备注：</span>'+remark+'</div>'
									html += '<div class="text"><span>PartsRemark：</span>'+partremark+'</div>'
									html += '</div>';
									
									// 推荐备件所需字段 ** 勿删！**
									var serviceNo = das.serviceNo==undefined?"":das.serviceNo;
									var info = {
										"Part_no":partNo,
										"Part_name":partName,
										"Part_qty":qty,
										"serviceNo":serviceNo,
									};
									recommendData.push(info);
									// ==========================
								}
								h("#beijian").html(html);
							}else{
								var html = '<div class="nodata">—— 暂无数据 ——</div>';
								h("#beijian").html(html);
							}
						} else {
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#beijian").html(html);
							app.toast(data.msg);
						}
					}, function(errorMsg) {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#beijian").html(html);
						app.toast("数据获取失败，请检查网络连接");
					});
				}

			}(mui, document));
			
			function getPlanState(){
				ajaxGet(BASE_URL + "cc/PlanDetails/getPlanDetails", {
					"ServiceNoticeId": ServiceNoticeId,
					"fseId": app.getUser().enginnerId
				}, function(data) {
					if (data.code == 200) {
						if(data.data!=""){
							var state = data.data.state;
							if(state!='0' && state!='6'){
								h("#anniu").show();
							}
						}
					}
				}, function(errorMsg) {
					console.log(JSON.stringify(errorMsg))
				});
			}
		</script>
		<!-- js代码 end -->

	</body>

</html>
